
<template>
  <el-dialog :close-on-click-modal="false" :title="$tt('label_confirm_completion')" :visible.sync="visible" custom-class="dialog_auto"
    v-loading="loading">

    <el-form :label-width="$globalCss.formLabelWidth_default" :model="form" :rules="rules" ref="Form">
      <el-form-item :label="$tt('label_tms_complete_date')" prop="completionTime">
        <ex_super_input v-model="form.completionTime" class="form_input_small" type="date-picker" :attrs="{
          'picker-options': {
            disabledDate: t => {
              return t.getTime() < now
            }
          }
        }" />
      </el-form-item>
      <el-form-item :label="$tt('label_tms_sign_person')" prop="sign">
        <ex_super_input v-model="form.sign" class="form_input_small"  />
      </el-form-item>


      <el-form-item :label="$tt('label_tms_sign_count')" prop="signBoxQtx">
        <ex_super_input v-model="form.signBoxQtx" class="form_input_small" type="input-number"  />
      </el-form-item>
      <el-form-item :label="$tt('label_tms_sign_order')" prop="signUpload">
        <ex_super_input v-model="form.signUpload" type="upload-img" :limit="1"  />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog_footer">
      <el-button @click="visible = false">{{ $tt('label_cancel') }}</el-button>
      <el-button type="primary" @click="submitReady">{{ $tt('label_submit') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>


const default_obj = {
  completionTime: null,//		long 	完成时间
  sign: null,//	string 	签收人
  signBoxQtx: null,//	integer 	签收数量（箱数）
  signUpload: null,//
}
import moment from 'moment-mini-ts'

export default {
  components: {},
  data() {
    return {

      now:moment().hour(0).minute(0).second(0).millisecond(0).subtract(1, 'second').valueOf(),
      visible: false,
      loading: false,
      form: _.cloneDeep(default_obj),

      item: null,
      rules: {
        completionTime: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
        sign: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },

        signUpload: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
        signBoxQtx: { required: true,type:"number", validator: (r, v, cb) => {
          if(Number.isNaN(Number(v))||!v){
            cb(this.$tt('tip_can_no_empty'))
          }else{
            cb()
          }
        }, trigger: 'blur' },
      },
    }
  },
  computed: {



  },
  methods: {


    show(item,) {
      this.visible = true
      this.item = item
      this.form = _.cloneDeep(default_obj)
    },

    submitReady() {
      this.$refs['Form'].validate((valid) => {
        if (valid) {
          this.submit()
        } else {
          this.$message.error(this.$tt('form_validate_error'))
          return false;
        }
      });
    },
    hide() {
      this.visible = false
    },
    submit() {
      this.$ajax({
        url: "/tms-api/waybill/TmsTaskInfoOperationRpc/confirmCompletion.json",
        method: 'post', type: 'json',
        loading: true,
        data: {
          id:this.item.id,
          version:this.item.version,
          ...this.form
        },
        success: (res) => {
          this.$message.success(this.$tt('tip_submit_success'))
          this.hide()
          this.$emit('submitSuccess')
        },
      })


    },

  }
}
</script>
